from fastapi import FastAPI, Depends
from configuration.config import PsychoSettings, ServerSettings

from myPsycho.security.secure import UsernameAuthBackend
from starlette.middleware import Middleware
from starlette.middleware.authentication import AuthenticationMiddleware

from myPsycho.api import scales_api

middleware = [Middleware(AuthenticationMiddleware,
                         backend=UsernameAuthBackend("openminds"))]

psycho_app = FastAPI(middleware=middleware)
psycho_app.include_router(scales_api.router)


def build_config():
    return PsychoSettings()


def fetch_config():
    return ServerSettings()


@psycho_app.get('/index')
def index_psycho(config: PsychoSettings = Depends(build_config),
                 fconfig: ServerSettings = Depends(fetch_config)):
    return {
        'project_name': config.application,
        'webmaster': config.webmaster,
        'created': config.created,
        'development_server': fconfig.development_server,
        'dev_port': fconfig.dev_port
        }
